// cpp/imageCache/LRUCache.h

//
// Created on 2024/8/21.
//
// Node APIs are not fully supported. To solve the compilation error of the interface cannot be found,
// please include "napi/native_api.h".

#ifndef IMAGECACHEDEMO_LRUCACHE_H
#define IMAGECACHEDEMO_LRUCACHE_H
#include <list>
#include <map>
#include <mutex>
#include <string>

class LRUCache {
public:
    LRUCache() {}
    LRUCache(size_t maxSize, const std::string &cacheDir) : maxSize(maxSize), cacheDir(cacheDir) {}
    bool get(const std::string &key, size_t &bufferSize);
    void init(size_t size, const std::string &cacheDir);
    void put(const std::string &key, size_t bufferSize);
    void restoreFromCacheDir(const std::string &cacheDir);

private:
    size_t maxSize;
    size_t currentSize;
    std::list<std::string> cacheList;
    std::map<std::string, std::pair<size_t, std::list<std::string>::iterator>> cacheMap;
    std::mutex cacheMutex;
    std::string cacheDir;
};

#endif // IMAGECACHEDEMO_LRUCACHE_H
